﻿using Magicodes.Logger;
using Magicodes.Logger.NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TXH.DataSync.Helper;

namespace TXH.DataSync
{
    class Program
    {
        public static LoggerBase Logger = new NLogLogger("Main");
        static void Main(string[] args)
        {
            Console.WriteLine("正在加载配置...");
            Logger.Log(LoggerLevels.Debug, "正在加载配置...");
            if (ConfigHelper.Init())
            {
                Console.WriteLine("配置加载完成，正在初始化同步任务...");
                Logger.Log(LoggerLevels.Debug, "配置加载完成，正在初始化同步任务...");
                Console.ForegroundColor = ConsoleColor.Green;
                StartTask(TaskHelper.Start());
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("配置项错误，执行失败...");
                Logger.Log(LoggerLevels.Debug, "配置项错误，执行失败...");
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("执行完毕，程序将在10秒后自动退出...");
            System.Threading.Thread.Sleep(10000);
        }

        private static void StartTask(bool isSuccess)
        {
            
            if (!isSuccess)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("===================================================================");
                Console.WriteLine("     任务执行完毕！存在错误，请查看错误日志...");
                Logger.Log(LoggerLevels.Debug, "任务执行完毕！存在错误，请查看错误日志...");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("===================================================================");
                Console.WriteLine("     任务执行完毕，同步成功！");
                Logger.Log(LoggerLevels.Debug, "任务执行完毕，同步成功！");
            }
            Console.WriteLine("===================================================================");
        }
    }
}
